#-*- encoding:utf-8 -*-
import random

# from flask import Flask

from commons import *
from constants import *

# app = Flask(__name__)

# @app.route("/smp/horseman/login")
def horseman_login(data):
    url = horseman_url + "horseman/userLogin/login"
    # data = {
    #           "loginAccount": "15364086951",
    #           "password": "88316675D7882E3FDBE066000273842C",
    #           "loginType": "1"
    #         }
    return getPost(url, None, data)

def report_pos(token, **kwargs):
    url = horseman_url + "horseman/lbs/report"
    data = {
              "currentLat": random.uniform(33.6, 34.6),
              "currentLng": random.uniform(108.60, 109.89),
              "lastLat": 0,
              "lastLng": 0
            }
    print("%s[%s]: %s" % (kwargs['info']['loginAccount'], token, data))
    return getPost(url, token, data)

def batch_report():
    for e in importUserPass():
        try:
            data = {}
            data['loginAccount'] = e[0]
            data['password'] = e[1]
            data['loginType'] = "1"
            login_result = horseman_login(data)
            if login_result is None:
                continue
            # print(login_result)
            if login_result.__contains__('data') \
                    and login_result['data'] is not None \
                    and login_result['data'].__contains__('token'):
                print(report_pos(login_result['data']['token'], info = data))
        except (Exception):
            print("内部异常，检查接口是否连通")
            continue
        except:
            print("未知异常")
            continue
    pass

def batch_reg():
    tele = 19999990000
    url = horseman_url + "horseman/userLogin/register"
    for i in range(9998):
        data = {}
        tele += 1
        data['mobile'] = str(tele)
        data['password'] = '123456'
        data['smsCode'] = '123456'
        print(getPost(url, None, data))


if __name__ == '__main__':
    # batch_reg()
    while True:
        batch_report()
    pass